<!--  -->
<template>
  <div class="zijinzhanbi">
    <div class="bingtu1" ref="bingtu1"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      options: {
        title: {
          text: "意见建议处理占比",
          left: "center",
          textStyle: {
            color: "#fff",
          },
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
          data: [],
          textStyle: {
            color: "#fff",
          },
        },
        series: [
          {
            name: "占比",
            type: "pie",
            radius: "60%",
            center: ["60%", "65%"],
            data: [],

            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
              normal: {
                color: function (params) {
                  //自定义颜色
                  var colorList = [
                    "#e161ae",
                    "#37a2d8",
                    "#64e1e3",
                    "#fedb5b",
                    "#fda07e",
                    "#ffc500",
                  ];
                  return colorList[params.dataIndex];
                },
              },
            },
          },
        ],
      },
    };
  },

  methods: {
    huoqushuju() {
      //获取当前日期
      var jintian = new Date();
      var nowY = jintian.getFullYear();
      var nowM = jintian.getMonth() + 1;
      var nowD = jintian.getDate();
      var enddate =
        nowY +
        "-" +
        (nowM < 10 ? "0" + nowM : nowM) +
        "-" +
        (nowD < 10 ? "0" + nowD : nowD); //当前日期

      //获取三十天前日期
      var jintianqian30 = new Date(jintian - 1000 * 60 * 60 * 24 * 30); //最后一个数字30可改，30天的意思
      var lastY = jintianqian30.getFullYear();
      var lastM = jintianqian30.getMonth() + 1;
      var lastD = jintianqian30.getDate();
      var startdate =
        lastY +
        "-" +
        (lastM < 10 ? "0" + lastM : lastM) +
        "-" +
        (lastD < 10 ? "0" + lastD : lastD);

      let param = new URLSearchParams();
      param.append("time", startdate + "~" + enddate);
      // 请求开始
      this.$axios
        .post("/leader/feedback/quhuantu", param)
        .then((response) => {
          for (var i in response.data.data.data) {
            this.options.legend.data.push(i);
            this.options.series[0].data.push({
              name: i,
              value: response.data.data.data[i],
            });
          }
          this.bingtu1();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    bingtu1() {
      var myChart = this.$echarts.init(this.$refs.bingtu1);
      myChart.setOption(this.options);
    },
  },

  mounted() {
    this.huoqushuju();
  },
};
</script>
<style lang='less' scoped>
.zijinzhanbi {
  height: 100%;
  padding: 15px;
}

.bingtu1 {
  height: 75%;
  padding: 0px;
}
</style>